package org.example.route.event.listener;

import org.example.route.event.OrderCancelEvent;
import org.example.route.event.OrderPayEvent;
import org.example.route.event.source.OrderCancelSource;
import org.example.route.event.source.OrderPaySource;
import org.example.route.mapper.SeatMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class SeatListener {

    @Autowired
    private SeatMapper seatMapper;

    //释放这个座位
    @Async
    @EventListener
    public void handleEvent(OrderCancelEvent orderCancelEvent)
    {
        OrderCancelSource orderCancelSource = orderCancelEvent.getOrderCancelSource();
        seatMapper.beReleased(orderCancelSource.getSeatId());


    }

    @Async
    @EventListener
    public void handleEvent(OrderPayEvent orderPayEvent)
    {
        OrderPaySource orderPaySource = orderPayEvent.getOrderPaySource();
        seatMapper.beOccupied(orderPaySource.getSeatId());

    }

}
